package cn.com.callback

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import cn.com.elite.EliteBean;
import cn.com.elite.Util;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONObject;

/**
 * @author ThinkPad
 */

public class update_receiptstatus implements ServiceBackInvoke {
    private static final Log log = LogFactory.getLog(update_receiptstatus.class);

    public String doCallBack(EliteBean eliteBean, HttpServletRequest request, HttpServletResponse response) {
        request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        log.debug("=========================================同步报汇款单状态===================================");
        def receivebody = Util.getRequestBody(request, 'utf-8'); //获取报文
        log.debug("报文：" + receivebody);
        JSONObject obj = JSONObject.fromObject(receivebody);
        obj = obj.get("content");
        try {
            def procedure = "{call sp_receiptbill_status(?,?,?,?,?,?)}";
            def input = new String[5];
            input[0] = obj.get("crm_code");
            input[1] = obj.get("erp_checknote");
            input[2] = obj.get("erp_approvestatus");
            input[3] = obj.get("erp_checkman");
            input[4] = obj.get("erp_checkdate");
            log.debug("input:" + input);
            def sqlresult = eliteBean.executeWithReturn(procedure, input, "dataSource");
            if (sqlresult == '1') {
                return "{\"code\":\"s001\",\"content\":\"\",\"msg\":\"\",\"rsp\":\"succ\",\"rspCode\":\"\",\"sub_msg\":\"报汇款状态更新成功！\"}"
            } else {
                return "{\"code\":\"e000005\",\"content\":\"\",\"msg\":\"\",\"rsp\":\"init interface fail\",\"rspCode\":\"\",\"sub_msg\":\"接口调用失败！\"}"
            }
        } catch (Exception e) {
            log.error("", e);
            return "{\"code\":\"e000005\",\"content\":\"\",\"msg\":\"\",\"rsp\":\"init interface fail\",\"rspCode\":\"\",\"sub_msg\":\"接口调用失败！\"}"
        }
    }
}